﻿using System.Collections.Generic;
using System.Runtime.Serialization;
using System;

namespace Bookvar.ObjectModel.Collections
{
    [Serializable]
    [KnownType(typeof(MainTopic))]
    public class TopicCollection : ObservableKeyedCollection<Guid, Topic>
    {
        private Topic parent;

        public TopicCollection()
        {
        }

        public TopicCollection( Topic parent )
        {
            this.parent = parent;
        }

        public TopicCollection( Topic parent, IEnumerable<Topic> topics )
            : base( new List<Topic>( topics ) )
        {
            this.parent = parent;
        }

        public Topic Parent
        {
            get { return parent; }
            set { parent = value; }
        }

        protected override void InsertItem( int index, Topic item )
        {
            item.Parent = parent;

            base.InsertItem( index, item );
        }

        protected override Guid GetKeyForItem( Topic item )
        {
            return item.ID;
        }
    }
}